package com.xc.controller.backend;

import com.xc.common.ServerResponse;
import com.xc.pojo.User;
import com.xc.pojo.UserBank;
import com.xc.service.IUserBankService;
import com.xc.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/24 4:49 PM
 */
@Controller
@RequestMapping("/admin/user/")
@Slf4j
public class AdminUserController {

    @Autowired
    IUserService iUserService;
    @Autowired
    IUserBankService iUserBankService;

    /**
     *  用户列表
     * @param realName
     * @param phone
     * @param agentId
     * @param accountType
     * @param pageNum
     * @param pageSize
     * @param request
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "realName",required = false) String realName
            , @RequestParam(value = "phone",required = false) String phone
            , @RequestParam(value = "agentId", required = false) Integer agentId
            , @RequestParam(value = "accountType", required = false) Integer accountType
            , @RequestParam(value = "pageNum", defaultValue = "1") int pageNum
            , @RequestParam(value = "pageSize", defaultValue = "10") int pageSize
            , HttpServletRequest request){
        return iUserService.listByAdmin(realName ,phone ,agentId ,accountType ,pageNum ,pageSize ,request);
    }

    /**
     *  查询用户详情
     * @param userId
     * @return
     */
    @RequestMapping("detail.do")
    @ResponseBody
    public ServerResponse detail(Integer userId){
        return iUserService.findByUserId(userId);
    }

    /**
     *  修改锁定状态
     * @param userId
     * @return
     */
    @RequestMapping("updateLock.do")
    @ResponseBody
    public ServerResponse updateLock(Integer userId){
        return iUserService.updateLock(userId);
    }

    /**
     *  修改用户资金
     * @param userId
     * @param amt
     * @param direction
     * @return
     */
    @RequestMapping("updateAmt.do")
    @ResponseBody
    public ServerResponse updateAmt(Integer userId , Integer amt , Integer direction){
        return iUserService.updateAmt(userId,amt,direction);
    }

    /**
     *  修改用户信息
     * @param user
     * @return
     */
    @RequestMapping("update.do")
    @ResponseBody
    public ServerResponse update(User user){
        return iUserService.update(user);
    }

    /**
     *  修改银行卡信息
     * @param userBank
     * @return
     */
    @RequestMapping("updateBank.do")
    @ResponseBody
    public ServerResponse updateBank(UserBank userBank){
        return iUserBankService.updateBankByAdmin(userBank);
    }

    /**
     *  添加模拟账户
     * @param request
     * @param phone
     * @param amt
     * @param pwd
     * @return
     */
    @RequestMapping("addSimulatedAccount.do")
    @ResponseBody
    public ServerResponse addSimulatedAccount(HttpServletRequest request,
                                              @RequestParam(value = "agentId",required = false) Integer agentId,
                                              @RequestParam("phone") String phone,
                                              @RequestParam("amt") String amt,
                                              @RequestParam("pwd") String pwd){
        return iUserService.addSimulatedAccount(agentId,phone,pwd,amt,request);
    }


    /**
     *  审核用户
     * @param state
     * @param authMsg
     *  int reg_active = 0;         //  注册
        int auth_active = 1;        //  提交激活
        int success_active = 2;     //  实名认证成功
        int fail_active = 3;        //  激活打回
     * @return
     */
    @RequestMapping("authByAdmin.do")
    @ResponseBody
    public ServerResponse authByAdmin(Integer userId,Integer state,String authMsg){
        return iUserService.authByAdmin(userId,state,authMsg);
    }

    /**
     *  获取银行卡
     * @param userId
     * @return
     */
    @RequestMapping("getBank.do")
    @ResponseBody
    public ServerResponse getBank(Integer userId){
        return iUserBankService.getBank(userId);
    }



}
